# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator
from jms.dws.dws_actual_taking_dt import jms_dws__dws_actual_taking_dt
from jms.dwd.oms.dwd_yl_oms_oms_order_incre_dt import jms_dwd__dwd_yl_oms_oms_order_incre_dt
from jms.dwd.tab import jms_dwd__dwd_barscan_send_dt
from jms.dwd.tab import jms_dwd__dwd_barscan_collect_dt
from jms.dim import jms_dim__dim_lmdm_sys_network_expand
from jms.dm.prescription.dm_prescription_reach_details_dt import jms_dm__dm_prescription_reach_details_dt
from jms.dwd.tab.dwd_tab_customer_monitor_deploy_dt import jms_dwd__dwd_tab_customer_monitor_deploy_dt
from jms.dwd.tab.dwd_tab_customer_monitor_vips_dt import jms_dwd__dwd_tab_customer_monitor_vips_dt
from jms.dim.dim_lmdm_sys_customer_addition import jms_dim__dim_lmdm_sys_customer_addition
#from jms.dwd.dwd_warhouse.dwd_wide_rank_basic_scaninfo_tms_dt import jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_a15,jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_b15
from jms.dwd.dwd_warhouse.dwd_wide_barscan_operations_hist_dt import jms_dwd__dwd_wide_barscan_operations_hist_dt

jms_dm__dm_customer_monitor_detail_dt = SparkSubmitOperator(
    task_id='jms_dm__dm_customer_monitor_detail_dt',
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='dm_customer_monitor_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    # sla=timedelta(hours=7),
    driver_memory='4G',
    executor_memory='12G',
    executor_cores=6,
    num_executors=30,
    pool_slots=5,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 50,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '4G',  # 堆外内存
          'spark.default.parallelism': 600,
          'spark.sql.shuffle.partitions': 600 ,
          'spark.shuffle.consolidateFiles': 'true',
          'spark.shuffle.memoryFraction': '0.8',
          'spark.shuffle.file.buffer':'64k',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=6',
          'spark.locality.wait.process':10   #默认3秒,
          #'spark.locality.wait':300 ,
          },
    # jars='hdfs:///scheduler/jms/spark/cp/dm_customer_monitor_detail_dt/common-1.0-SNAPSHOT.jar',  # 依赖 jar 包
    jars='hdfs:///scheduler/jms/spark/wangbiao/dm_customer_monitor_detail_dt/common-1.0-SNAPSHOT.jar',  # 依赖 jar 包
    java_class='com.yunlu.bigdata.jobs.export.CustomerMonitorDetail',  # spark 主类
    # application='hdfs:///scheduler/jms/spark/cp/dm_customer_monitor_detail_dt/original-jobs-1.0-SNAPSHOT.jar',
    application='hdfs:///scheduler/jms/spark/wangbiao/dm_customer_monitor_detail_dt/original-jobs-1.0-SNAPSHOT.jar',
    # spark jar 包
    application_args=['{{ execution_date | cst_ds }}'],
    #execution_timeout=timedelta(hours=3)
    #excel平均时长:16分44秒
    #execution_timeout = timedelta(minutes=60)
    #excel平均时长:16分44秒
    execution_timeout = timedelta(minutes=60),
)

jms_dm__dm_customer_monitor_detail_dt << [
    jms_dwd__dwd_yl_oms_oms_order_incre_dt,
    jms_dws__dws_actual_taking_dt,
    jms_dwd__dwd_barscan_send_dt,
    jms_dwd__dwd_barscan_collect_dt,
    jms_dim__dim_lmdm_sys_network_expand,
    jms_dm__dm_prescription_reach_details_dt,
    jms_dwd__dwd_tab_customer_monitor_deploy_dt,
    jms_dwd__dwd_tab_customer_monitor_vips_dt,
    jms_dim__dim_lmdm_sys_customer_addition,
    #jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_a15,
    #jms_dwd__dwd_wide_rank_basic_scaninfo_tms_dt_b15
    jms_dwd__dwd_wide_barscan_operations_hist_dt
]
